package com.sky.sky_server.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import com.sky.sky_pojo.entity.ShoppingCart;

@Mapper
public interface ShoppingCartMapper {

    /**
     * 根据查询条件查询购物车
     * ____动态查询条件：dishId、setmealId、userId
     * @param shoppingCart
     * @return
     */
    List<ShoppingCart> selectByDishIdOrSetmealId(ShoppingCart shoppingCart);

    /**
     * 修改购物车
     * @param shoppingCart
     * @return
     */
    int update(ShoppingCart shoppingCart);

    /**
     * 添加购物车
     * @param shoppingCart
     * @return
     */
    @Insert("insert into shopping_cart (name,image,user_id,dish_id,setmeal_id,dish_flavor,number,amount,create_time) values (#{name},#{image},#{userId},#{dishId},#{setmealId},#{dishFlavor},#{number},#{amount},#{createTime})")
    int insert(ShoppingCart shoppingCart);

    /**
     * 查看购物车
     * @param userId
     * @return
     */
    @Select("select * from shopping_cart where user_id = #{userId}")
    List<ShoppingCart> list(Long userId);

    /**
     * 删除购物车内的一个商品
     * @param shoppingCartDTO
     * @return
     */
    int delete(ShoppingCart shoppingCart);

    /**
     * 清空购物车
     * @param userId
     */
    @Delete("delete from shopping_cart where user_id = #{userId}")
    void clean(Long userId);
    
}
